package com.itheima.Classs;

import com.itheima.domain.Student;

import java.util.ArrayList;

public class TestStudent02 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = new Student("张三丰", 17);list.add(stu1);
        Student stu2 = new Student("张三丰2", 18);list.add(stu2);
        Student stu3 = new Student("张三丰3", 19);list.add(stu3);
        ArrayList<Student> list1 = getList(list);
        for (int i = 0; i < list1.size(); i++) {
            Student s = list1.get(i);
            System.out.println(s.getName() + "..." + s.getAge());
        }
    }

    public static ArrayList<Student> getList(ArrayList<Student> list) {
        ArrayList<Student> newlist = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            int age = stu.getAge();
            if (age >=18) {
                newlist.add(list.get(i));
            }
        }
        return newlist;

    }
}
